<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="js/jquery.js"></script>
    <script>
      function getDataFromServer(url) {
        return new Promise((resolve, reject) => {
          $.ajax({
            url: url,
            dataType:"json",
            success: function (res) {
              if (res.success) {
                resolve('请求获取数据成功.res='+ JSON.stringify(res));
              } else {
                reject("请求获取失败");
              }
            },
          });
        });
      }

      $(function () {
        $("button").click(function () {
          getDataFromServer("http://127.0.0.1:3001/getdata1")
            .then((data) => {
              console.log("01----"+data);
              return getDataFromServer("http://127.0.0.1:3001/getdata2");
            })
            .then((data) => {
              console.log("02----"+data);
            });
        });
      });
    </script>
  </head>
  <body>
    <button>点我发送请求</button>
  </body>
</html>
